********************************************************************************
*																		       *
* 							VAP								 				   *
*								     									       *
********************************************************************************

* -----> This do-file: All tables and graphs using CBOS data

********************************************************************************


*** path ***

if "`c(username)'"=="Juan S. Morales" | "`c(username)'"=="jmorales"{
	global PathData = "C:/Users/`c(username)'/Dropbox/adamowicz/4_Draft/CPS_FINAL_submission/Data/"
	global PathFig = "C:/Users/`c(username)'/Dropbox/adamowicz/4_Draft/CPS_FINAL_submission/Figures/"
	global PathTab = "C:/Users/`c(username)'/Dropbox/adamowicz/4_Draft/CPS_FINAL_submission/Tables/"
	}
else { 
	global PathData = "/Users/JNG/Dropbox/adamowicz/4_Draft/CPS_FINAL_submission/Data/"
	global PathFig = "/Users/JNG/Dropbox/adamowicz/4_Draft/CPS_FINAL_submission/Figures/"
	global PathTab = "/Users/JNG/Dropbox/adamowicz/4_Draft/CPS_FINAL_submission/Tables/"
	} 

use "${PathData}cbos_final.dta", clear


*** recode ***

label variable treat2 "Post"
label define treat 1 "After attack" 0 "Before attack"
label values treat2 treat

label variable q156 "Internet User"
label define user 1 "Internet user" 2 "No Internet user"
label values q156 user

rename q156 internet

replace party1=0 if party1==.
replace party2=0 if party2==.
replace party3=0 if party3==.
replace party4=0 if party4==.
replace party5=0 if party5==.
replace party6=0 if party6==.
replace party7=0 if party7==.
replace party8=0 if party8==.
replace party9=0 if party9==.
replace party10=0 if party10==.
replace party11=0 if party11==.

replace pp1=0 if pp1==.
replace pp2=0 if pp2==.
replace pp8=0 if pp8==.
replace pp3=0 if pp3==.
replace pp4=0 if pp4==.
replace pp5=0 if pp5==.
replace pp6=0 if pp6==.
replace pp7=0 if pp7==.

gen party22=1 if party2==1 | party8==1
replace party22 = 0  if party22!=1

gen pp22=1 if pp2==1 | pp8==1
replace pp22 = 0  if pp22!=1

pca party1 party2 party3 party4 party5 party6 party7 party8 party9 party10 party11
predict pca1

gen voteIntent = -1 if party1==1
replace voteIntent = 1 if party2==1 | party8==1
replace voteIntent = 0 if voteIntent==.

gen oppTV=1 if q157==1 | q157==2
replace oppTV=0 if oppTV==. & q157!=.
label variable oppTV "Pro-Opp TV channel"
label define inout0 1 "Pro-Opp" 0 "No Pro-Opp"
label values oppTV inout0

gen TV=1 if q157==1 | q157==2
replace TV=2 if q157==6
replace TV=3 if q157==3 | q157==4 | q157==5 | q157==7
label variable TV "TV channel"
label define inout 1 "Pro-Opp" 2 "Neutral" 3 "Pro-Gov"
label values TV inout
tab TV, gen(tv)
label values tv1 inout0

recode DochOs 0=0 1 2=1 3 4=2 5 6=3 7/100=9, gen(income)
tab income, gen(income)

gen voter=1 if qq35!=.
replace voter=0 if qq35==.


append using "${PathData}cbos_feb19.dta"  
append using "${PathData}cbos_dec18.dta"  

replace wave=2 if wave==.

tostring data, replace format(%20.0f)

replace day = 9 if data=="21527"
replace day = 8 if data=="21526"
replace day = 7 if data=="21525"
replace day = 6 if data=="21524"
replace day = 5 if data=="21523"
replace day = 4 if data=="21522"
replace day = 3 if data=="21521"
replace day = 2 if data=="21520"
replace day = 1 if data=="21519"
replace day = 0 if data=="21518"
replace day = -1 if data=="21517"

replace day = 18 if data=="21587"
replace day = 19 if data=="21588"
replace day = 20 if data=="21589"
replace day = 21 if data=="21590"
replace day = 22 if data=="21591"
replace day = 23 if data=="21592"
replace day = 24 if data=="21593"
replace day = 25 if data=="21594"
replace day = 26 if data=="21600"

gen DoW = 1 if day==14 	| day==22 | day==3
replace DoW = 2 if day==15 | day==23 | day==4
replace DoW = 3 if day==16 | day==24 | day==5
replace DoW = 4 if day==10 | day==25 | day==17 | day==18 | day==6 | day==-1
replace DoW = 5 if day==11 | day==26 | day==19 | day==7 | day==0
replace DoW = 6 if day==12 | day==27 | day==20 | day==8 | day==1
replace DoW = 7 if day==13 | day==21 | day==9  | day==2

recode DoW 1/5=0 6/7=1, gen(weekend)

replace day = day+1

gen wave1 = wave==1
gen wave3 = wave==3

gen inter = treat2*tv2

tab q151, gen(marital)

zval plec urodzony q151 income educ voter pp1 pp2 size4 size1 marital1 marital2 treat2 internet




***** TABLES ******


*** Table 3 ***

eststo clear
eststo, title("PCA"): teffects psmatch (pca1) (treat2 tv1 pp1 pp22 internet educ1 size1 size2 size4, probit) if wave==2, caliper(0.5)
estadd local modelN = "Matching"
estadd local waves = "1"
estadd local regionFE = "No"
estadd local waveFE = "No"
eststo, title("Ordinal"): teffects psmatch (voteIntent) (treat2 tv1 pp1 pp22 internet educ1 size1 size2 size4, probit) if wave==2, caliper(0.5)
estadd local modelN = "Matching"
estadd local waves = "1"
estadd local regionFE = "No"
estadd local waveFE = "No"
eststo, title("GovSup"): teffects psmatch (party1) (treat2 tv1 pp1 pp22 internet educ1 size1 size2 size4, probit) if wave==2, caliper(0.5)
estadd local modelN = "Matching"
estadd local waves = "1"
estadd local regionFE = "No"
estadd local waveFE = "No"
eststo, title("OppSup"): teffects psmatch (party22) (treat2 tv1 pp1 pp22 internet educ1 size1 size2 size4, probit) if wave==2, caliper(0.5)
estadd local modelN = "Matching"
estadd local waves = "1"
estadd local regionFE = "No"
estadd local waveFE = "No"
eststo, title("PCA"): reghdfe pca1 treat2 tv1 pp1 pp22 internet educ1 size2 size3 size4 weekend wave1 wave3, abs(woj)
estadd local modelN = "OLS"
estadd local waves = "3"
estadd local regionFE = "Yes"
estadd local waveFE = "Yes"
eststo, title("Ordinal"): reghdfe voteIntent treat2 tv1 pp1 pp22 internet educ1 size2 size3 size4 weekend wave1 wave3, abs(woj)
estadd local modelN = "OLS"
estadd local waves = "3"
estadd local regionFE = "Yes"
estadd local waveFE = "Yes"
eststo, title("GovSup"): reghdfe party1 treat2 tv1 pp1 pp22 internet educ1 size2 size3 size4 weekend wave1 wave3, abs(woj)
estadd local modelN = "OLS"
estadd local waves = "3"
estadd local regionFE = "Yes"
estadd local waveFE = "Yes"
eststo, title("OppSup"): reghdfe party22 treat2 tv1 pp1 pp22 internet educ1 size2 size3 size4 weekend wave1 wave3, abs(woj)
estadd local modelN = "OLS"
estadd local waves = "3"
estadd local regionFE = "Yes"
estadd local waveFE = "Yes"
esttab using "${PathTab}Table3.tex", b(3) se(3) drop(tv1 pp1 pp22 internet educ1 size2 size3 size4 weekend wave1 wave3) star(* 0.1 ** 0.05 *** 0.01) stats(N modelN waves regionFE waveFE, fmt(0) labels("N" "Model" "Survey Waves" "Region FE" "Wave FE")) label nodepvar mtitles title("Violent attack and vote intentions"} \footnotesize {) replace nonotes postfoot(" ")



*** Table 4 ***


eststo clear
eststo, title("PCA"): teffects psmatch (pca1) (treat2 tv1 pp1 pp22 internet educ1 size1 size2 size4, probit) if tv2==1 & wave==2, caliper(0.5)
estadd local modelN = "Matching"
estadd local controls = "Neutral TV"
eststo, title("Ordinal"): teffects psmatch (voteIntent) (treat2 tv1 pp1 pp22 internet educ1 size1 size2 size4, probit) if tv2==1 & wave==2, caliper(0.5)
estadd local modelN = "Matching"
estadd local controls = "Neutral TV"
eststo, title("PCA"): reghdfe pca1 treat2 tv1 pp1 pp22 internet educ1 size2 size3 size4 weekend wave1 wave3 if tv2==1, abs(woj)
estadd local modelN = "OLS"
estadd local controls = "Neutral TV"
eststo, title("Ordinal"): reghdfe voteIntent treat2 tv1 pp1 pp22 internet educ1 size2 size3 size4 weekend wave1 wave3 if tv2==1, abs(woj)
estadd local modelN = "OLS"
estadd local controls = "Neutral TV"

eststo, title("PCA"): teffects psmatch (pca1) (treat2 tv1 pp1 pp22 internet educ1 size1 size2 size4, probit) if tv2==0 & wave==2, caliper(0.5)
estadd local modelN = "Matching"
estadd local controls = "Partisan TV"
eststo, title("Ordinal"): teffects psmatch (voteIntent) (treat2 tv1 pp1 pp22 internet educ1 size1 size2 size4, probit) if tv2==0 & wave==2, caliper(0.5)
estadd local modelN = "Matching"
estadd local controls = "Partisan TV"
eststo, title("PCA"): reghdfe pca1 treat2 tv1 pp1 pp22 internet educ1 size2 size3 size4 weekend wave1 wave3 if tv2==0, abs(woj)
estadd local modelN = "OLS"
estadd local controls = "Partisan TV"
eststo, title("Ordinal"): reghdfe voteIntent treat2 tv1 pp1 pp22 internet educ1 size2 size3 size4 weekend wave1 wave3 if tv2==0, abs(woj)
estadd local modelN = "OLS"
estadd local controls = "Partisan TV"

esttab using "${PathTab}Table4.tex", b(3) se(3) drop(tv1 pp1 pp22 internet educ1 size2 size3 size4 weekend wave1 wave3) star(* 0.1 ** 0.05 *** 0.01) stats(N modelN controls, fmt(0) labels("N" "Model" "Sample")) label nodepvar mtitles title("Violent attack and vote intentions (by TV viewership)} \footnotesize {") replace nonotes postfoot(" ")



*** Table A19 ***


eststo clear
eststo, title("Reports party preferences"): reg voter treat2 if wave==2
estadd local controls = "No"
esttab using "${PathTab}TableA19.tex", b(3) se(3) star(* 0.1 ** 0.05 *** 0.01) keep(treat2) stats(N controls, fmt(0) labels("N" "Controls")) label nodepvar mtitles title("Violent attack and attrition") replace nonotes postfoot(" ")



*** Table A22 ***

eststo clear
eststo, title("PCA"): reghdfe pca1 treat2 tv1 pp1 pp22 internet educ1 size2 size3 size4 if wave==2, abs(woj)
estadd local modelN = "OLS"
estadd local waves = "1"
estadd local regionFE = "Yes"
estadd local waveFE = "No"
estadd local trends = "No"
eststo, title("Ordinal"): reghdfe voteIntent treat2 tv1 pp1 pp22 internet educ1 size2 size3 size4 if wave==2, abs(woj)
estadd local modelN = "OLS"
estadd local waves = "1"
estadd local regionFE = "Yes"
estadd local waveFE = "No"
estadd local trends = "No"
eststo, title("GovSup"): reghdfe party1 treat2 tv1 pp1 pp22 internet educ1 size2 size3 size4 if wave==2, abs(woj)
estadd local modelN = "OLS"
estadd local waves = "1"
estadd local regionFE = "Yes"
estadd local waveFE = "No"
estadd local trends = "No"
eststo, title("OppSup"): reghdfe party22 treat2 tv1 pp1 pp22 internet educ1 size2 size3 size4 if wave==2, abs(woj)
estadd local modelN = "OLS"
estadd local waves = "1"
estadd local regionFE = "Yes"
estadd local waveFE = "No"
estadd local trends = "No"
eststo, title("PCA"): reghdfe pca1 treat2 tv1 pp1 pp22 internet educ1 size2 size3 size4 weekend day, abs(woj)
estadd local modelN = "OLS"
estadd local waves = "3"
estadd local regionFE = "Yes"
estadd local waveFE = "No"
estadd local trends = "Yes"
eststo, title("Ordinal"): reghdfe voteIntent treat2 tv1 pp1 pp22 internet educ1 size2 size3 size4 weekend day, abs(woj)
estadd local modelN = "OLS"
estadd local waves = "3"
estadd local regionFE = "Yes"
estadd local waveFE = "No"
estadd local trends = "Yes"
eststo, title("GovSup"): reghdfe party1 treat2 tv1 pp1 pp22 internet educ1 size2 size3 size4 weekend day, abs(woj)
estadd local modelN = "OLS"
estadd local waves = "3"
estadd local regionFE = "Yes"
estadd local waveFE = "No"
estadd local trends = "Yes"
eststo, title("OppSup"): reghdfe party22 treat2 tv1 pp1 pp22 internet educ1 size2 size3 size4 weekend day, abs(woj)
estadd local modelN = "OLS"
estadd local waves = "3"
estadd local regionFE = "Yes"
estadd local waveFE = "No"
estadd local trends = "Yes"
esttab using "${PathTab}TableA22.tex", b(3) se(3) drop(tv1 pp1 pp22 internet educ1 size2 size3 size4 weekend day) star(* 0.1 ** 0.05 *** 0.01) stats(N modelN waves regionFE waveFE trends, fmt(0) labels("N" "Model" "Survey Waves" "Region FE" "Wave FE" "Linear trend")) label nodepvar mtitles title("Violent attack and vote intentions (linear trends)"} \footnotesize {) replace nonotes postfoot(" ")


**** Table A23 ****


eststo clear
eststo, title("PCA"): teffects psmatch (pca1) (treat2 tv1 pp1 pp22 internet educ1 size1 size2 size4, probit) if wave==2 & day!=9 & day!=10, caliper(0.5)
estadd local modelN = "Matching"
estadd local waves = "1"
estadd local regionFE = "No"
estadd local waveFE = "No"
eststo, title("Ordinal"): teffects psmatch (voteIntent) (treat2 tv1 pp1 pp22 internet educ1 size1 size2 size4, probit) if wave==2 & day!=9 & day!=10, caliper(0.5)
estadd local modelN = "Matching"
estadd local waves = "1"
estadd local regionFE = "No"
estadd local waveFE = "No"
eststo, title("GovSup"): teffects psmatch (party1) (treat2 tv1 pp1 pp22 internet educ1 size1 size2 size4, probit) if wave==2 & day!=9 & day!=10, caliper(0.5)
estadd local modelN = "Matching"
estadd local waves = "1"
estadd local regionFE = "No"
estadd local waveFE = "No"
eststo, title("OppSup"): teffects psmatch (party22) (treat2 tv1 pp1 pp22 internet educ1 size1 size2 size4, probit) if wave==2 & day!=9 & day!=10, caliper(0.5)
estadd local modelN = "Matching"
estadd local waves = "1"
estadd local regionFE = "No"
estadd local waveFE = "No"
eststo, title("PCA"): reghdfe pca1 treat2 tv1 pp1 pp22 internet educ1 size2 size3 size4 weekend wave1 wave3 if day!=9 & day!=10, abs(woj)
estadd local modelN = "OLS"
estadd local waves = "3"
estadd local regionFE = "Yes"
estadd local waveFE = "Yes"
eststo, title("Ordinal"): reghdfe voteIntent treat2 tv1 pp1 pp22 internet educ1 size2 size3 size4 weekend wave1 wave3 if day!=9 & day!=10, abs(woj)
estadd local modelN = "OLS"
estadd local waves = "3"
estadd local regionFE = "Yes"
estadd local waveFE = "Yes"
eststo, title("GovSup"): reghdfe party1 treat2 tv1 pp1 pp22 internet educ1 size2 size3 size4 weekend wave1 wave3 if day!=9 & day!=10, abs(woj)
estadd local modelN = "OLS"
estadd local waves = "3"
estadd local regionFE = "Yes"
estadd local waveFE = "Yes"
eststo, title("OppSup"): reghdfe party22 treat2 tv1 pp1 pp22 internet educ1 size2 size3 size4 weekend wave1 wave3 if day!=9 & day!=10, abs(woj)
estadd local modelN = "OLS"
estadd local waves = "3"
estadd local regionFE = "Yes"
estadd local waveFE = "Yes"
esttab using "${PathTab}TableA23.tex", b(3) se(3) drop(tv1 pp1 pp22 internet educ1 size2 size3 size4 weekend wave1 wave3) star(* 0.1 ** 0.05 *** 0.01) stats(N modelN waves regionFE waveFE, fmt(0) labels("N" "Model" "Survey Waves" "Region FE" "Wave FE")) label nodepvar mtitles title("Violent attack and vote intentions (data from the 5th and 6th survey day before the event dropped)"} \footnotesize {) replace nonotes postfoot(" ")



*** Table A24 ***


eststo clear
eststo, title("PCA"): reghdfe pca1 treat2 tv2 inter tv1 pp1 pp22 internet educ1 size2 size3 size4 if wave==2, abs(woj)
estadd local controls = "Yes"
eststo, title("Ordinal"): reghdfe voteIntent treat2 tv2 inter tv1 pp1 pp22 internet educ1 size2 size3 size4 if wave==2, abs(woj)
estadd local controls = "Yes"
eststo, title("GovSup"): reghdfe party1 treat2 tv2 inter tv1 pp1 pp22 internet educ1 size2 size3 size4 if wave==2, abs(woj)
estadd local controls = "Yes"
eststo, title("OppSup"): reghdfe party22 treat2 tv2 inter tv1 pp1 pp22 internet educ1 size2 size3 size4 if wave==2, abs(woj)
estadd local controls = "Yes"

esttab using "${PathTab}TableA24.tex", b(3) se(3) star(* 0.1 ** 0.05 *** 0.01) keep(treat2 tv2 inter) stats(N controls, fmt(0) labels("N" "Controls")) label nodepvar mtitles title("Violent attack and vote intentions (interaction with TV viewership)") replace nonotes postfoot(" ")





******* FIGURES *******


**** Figure 5 ****

fvset base 14 day
reghdfe voteIntent i.day , abs(woj weekend)
preserve	
	regsave, ci
	gen days = _n
	replace days = days-15
	drop if days>13
	drop if days==0
	graph twoway (lpoly coef days if days<0, lp(dash) bwidth(7) color(black) msize(small)) (lpolyci coef days if days<0, pwidth(7) level(90) bwidth(7) lwidth(none) color(gray%20)) (lpolyci coef days if days>0, pwidth(7) level(90) bwidth(7) lwidth(none) color(gray%20)) (scatter coef days, msymbol(triangle) color(black) msize(small)) (lpoly coef days if days>0, lp(dash) bwidth(7) color(gray) msize(small) graphregion(color(white)) legend(off) ytitle("Opp-vs-Gov Support", size(large)) xtitle("Survey-days since event", size(large)) lwidth(0.3 0.3) color(black) tline(0.5, lwidth(23) lp(solid) lc(gray%10)) tline(0.5, lp(solid) lc(black)) graphregion(lwidth(large)))
	graph export "${PathFig}Figure5.png", as(png) replace
restore



*** Figure A12 ***


eststo clear
eststo Gender: reg  z_plec z_treat2 if wave==2 
eststo Age:  reg  z_urodzony z_treat2 if wave==2 
eststo Married: reg  z_marital2 z_treat2 if wave==2 
eststo Income: reg  z_income z_treat2 if wave==2
eststo No_education: reg  z_educ z_treat2 if wave==2 
eststo Village: reg  z_size1 z_treat2 if wave==2
eststo Mid_city: reg  z_size4 z_treat2 if wave==2
eststo Voter: reg  z_voter z_treat2 if wave==2 
eststo Voted_gov_15: reg  z_pp1  z_treat2 if wave==2
eststo Voted_opp_15: reg  z_pp2  z_treat2 if wave==2
eststo Internet_user: reg  z_internet z_treat2 if wave==2

coefplot Gender || Age || Married || Income || No_education || Village || Mid_city || Voter || Voted_gov_15 || Voted_opp_15 || Internet_user, keep(z_treat2) xline(0) horizontal bycoefs byopts(xrescale) level(95 90) title("Balance test") nolabel legend(off) 
	graph export "${PathFig}FigureA12.png", as(png) replace



*** Figure A13 ***

teffects psmatch (voteIntent) (treat2 tv1 pp1 pp22 internet educ1 size1 size2 size4, probit), caliper(0.5)

psmatch2 treat2 tv1 pp1 pp22 internet educ1 size1 size2 size4
pstest, both graph



**** Figure A14 ****

*** pis ***

fvset base 14 day
reghdfe party1 i.day , abs(woj weekend)
preserve	
	regsave, ci
	gen days = _n
	replace days = days-15
	drop if days>13
	drop if days==0

	graph twoway (lpoly coef days if days<=0, lp(dash) bwidth(7) color(gray) msize(small)) (lpoly coef days if days>0, lp(dash) bwidth(7) color(gray) msize(small)) (lpolyci coef days if days<=0, pwidth(7) level(90) bwidth(7) lwidth(none) color(gray%20)) (lpolyci coef days if days>0, pwidth(7) level(90) bwidth(7) lwidth(none) color(gray%20)) (scatter coef days, msymbol(triangle) msize(small) graphregion(color(white)) legend(off) ytitle("Government Support", size(large)) xtitle("Survey-days since event", size(large)) lwidth(0.3 0.3) color(black) tline(0.5, lwidth(23) lp(solid) lc(gray%10)) tline(0.5, lp(solid) lc(black)) graphregion(lwidth(large)))
	graph export "${PathFig}FigureA14a.png", as(png) replace
restore

*** PO ***

fvset base 14 day
reghdfe party2 i.day , abs(woj weekend)
preserve	
	regsave, ci
	gen days = _n
	replace days = days-15
	drop if days>13
	drop if days==0

	graph twoway (lpoly coef days if days<=0, lp(dash) bwidth(7) color(gray) msize(small)) (lpoly coef days if days>0, lp(dash) bwidth(7) color(gray) msize(small)) (lpolyci coef days if days<=0, pwidth(7) level(90) bwidth(7) lwidth(none) color(gray%20)) (lpolyci coef days if days>0, pwidth(7) level(90) bwidth(7) lwidth(none) color(gray%20)) (scatter coef days, msymbol(triangle) msize(small) graphregion(color(white)) legend(off) ytitle("Opposition Support", size(large)) xtitle("Survey-days since event", size(large)) lwidth(0.3 0.3) color(black) tline(0.5, lwidth(23) lp(solid) lc(gray%10)) tline(0.5, lp(solid) lc(black)) graphregion(lwidth(large)))
	graph export "${PathFig}FigureA14b.png", as(png) replace
restore



*** Figure A18 ***

graph bar (mean) pp1 party1 pp22 party22 , over(TV)


